package com.p2p.service.operationsManagementService.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.p2p.common.base.RespResult;
import com.p2p.common.base.RespResultCode;
import com.p2p.entity.RedPacketsManage;
import com.p2p.mapper.RedPacketsManageMapper;
import com.p2p.service.operationsManagementService.RedPacketsManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RedPacketsManageServiceImpl implements RedPacketsManageService {

    @Autowired
    private RedPacketsManageMapper redPacketsManageMapper;

    @Override
    public RespResult RedPacketsManageList(Integer currentPage, Integer pageSize) {
        if (currentPage != null && pageSize != null){
            Page<RedPacketsManage> page = new Page<>(currentPage,pageSize);
            QueryWrapper<RedPacketsManage> queryWrapper = new QueryWrapper();
            queryWrapper.eq("is_deleted",0);
            Page<RedPacketsManage> redPacketsManagePage = redPacketsManageMapper.selectPage(page, queryWrapper);
            return RespResult.success(redPacketsManagePage);
        }
        return RespResult.error(RespResultCode.ERR_PARAM_NOT_LEGAL.getCode(),RespResultCode.ERR_PARAM_NOT_LEGAL.getMessage(),null);
    }

    @Override
    public RespResult addRedPacket(RedPacketsManage redPacketsManage) {
        int i = redPacketsManageMapper.insert(redPacketsManage);
        if (i > 0){
            return RespResult.success();
        }
        return RespResult.error(RespResultCode.ERR_PARAM_NOT_LEGAL.getCode(),RespResultCode.ERR_PARAM_NOT_LEGAL.getMessage(),null);
    }
//    @Override
//    public RespResult search(RedPacketsManage redPocketsManage,Integer currentPage,Integer pageSize) {
//        Page<RedPacketsManage> page = new Page<>(currentPage,pageSize);
//        String name = redPocketsManage.getName();
//        Byte type = redPocketsManage.getType();
//        List<RedPacketsManage> search = redPacketsManageMapper.search(name, type, page);
//        if (search.size() > 0){
//            return RespResult.success(search);
//        }
//        return RespResult.error(RespResultCode.ERR_PARAM_NOT_LEGAL.getCode(),RespResultCode.ERR_PARAM_NOT_LEGAL.getMessage(),null);
//    }

}
